#ifndef PROTOBUF_PACKAGE_H
#define PROTOBUF_PACKAGE_H

#include "package_surpport.h"

#define RegisterProtoBufPackage(name)  \
	DoJobOnInitializing(name##Pack, \
	boost::bind(&PackageMgr::add, PackageMgr::getInstace(), boost::shared_ptr<IPackage>(new name##Pack()))); \
	PoolSurpportImp(name##Pack)

#define ProtoBufPackage(Name, ID) \
	class Name##Pack : public ProtoBufPackage<Name, Name##Pack, ID>

template<typename ProtoMessage, typename Sub, int ID>
class ProtoBufPackage : public PoolSurpport<Sub>, public ClonablePackage<Sub>
{
	ProtoMessage message;
public:
	virtual void poll(istream& is)
	{
		message.ParseFromIstream(&is);
	}

	virtual void push(ostream& os)
	{
		message.SerializeToOstream(&os);
	}

	virtual size_t size() const
	{
		return message.ByteSize();
	}

	virtual size_t messageID() const
	{
		return ID;
	}

	inline ProtoMessage& getMessage(){ return message; }

	virtual void handle(boost::shared_ptr<IIoHandler> ioHandler){}
	virtual ~ProtoBufPackage<ProtoMessage, Sub, ID>(){}
};

#endif
